C If-Else Statement

The if-else statement is used to verify the given condition and executes only one out of the two blocks of statements based on the condition result.

Flowchart for If-Else Statement

Syntax for If-Else Statement


if (condition) {
    ...
    True block of statements;
    ...
} else {
    ...
    False block of statements;
    ...
}

            

Example


#include < stdio.h>

void main() {
    int number = -5;

    if (number > 0) {
        printf("The number is positive.\n");
    } else {
        printf("The number is negative or zero.\n");
    }
}